<?php 
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]***[即时到账云端连接函数Api]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 零度  <2109877665@qq.com>
// +----------------------------------------------------------------------
// | Date: 2018年01月24日
// +----------------------------------------------------------------------

//引用服务器URL列表文件
require_once('Instant_Url_List.php');

require_once('TenpayHttpClient.class.php');//通讯引用文件

class Instant_Api {
    protected $Api_url 	= null;
    protected $Api_pid = null;
    protected $Api_key = null;
    function __construct($Api_url = 'http://www.qqmzz.cn/',$Api_pid = null,$Api_key = null)
    {
        $this->Apikey	= 1234567890;//接口对接密钥
        $this->Api_url 	= $Api_url;
        $this->Api_pid  = $Api_pid;
        $this->Api_key  = $Api_key;
		
		//通信对象
        $this->httpClient  = new TenpayHttpClient();
		$this->httpClient->setTimeOut(5);//超时时间
    }
	
    
    /**
     * 获取即时到帐云端资料
	 * 提交参数:pid,key
     */
    function Query($pid = null,$key = null)
    {
		if($pid and $key){
			$Arrs = array("act" =>'query',"apikey" =>$this->Apikey,"pid" =>$pid,"key" =>$key);
		}else{
			$Arrs = array("act" =>'query',"apikey" =>$this->Apikey,"pid" =>$this->Api_pid,"key" =>$this->Api_key);
		}
		//设置请求内容
		$this->httpClient->setReqContent($this->Api_url.'api/instant_api.php?'.http_build_query($Arrs));
		//后台调用
		if($this->httpClient->call()) {
			//设置结果参数
			$json = json_decode($this->httpClient->getResContent(),true);
		}
		return $json;
    }  
    /**
     * 记录订单
	 * 提交参数:用户ID,付款超时 单位：秒,云支付订单号,商户订单号,异步通知地址,支付方式,名称,金额
     */
    function Submit($pay_id,$outtime,$trade_no,$out_trade_no,$notify_url,$type,$name,$money,$sign)
    {
        $Arrs = array("act" =>'submit',"apikey" =>$this->Apikey,"pid" =>$this->Api_pid,"key" =>$this->Api_key,"pay_id" =>$pay_id,"outtime" =>$outtime,"trade_no" =>$trade_no,"out_trade_no" =>$out_trade_no,"notify_url" =>$notify_url,"type" =>$type,"name" =>$name,"money" =>$money,"sign" =>$sign);
		//设置请求内容
        $this->httpClient->setReqContent($this->Api_url.'api/instant_api.php?'.http_build_query($Arrs));
		//后台调用
		if($this->httpClient->call()) {
			//设置结果参数
			$json = json_decode($this->httpClient->getResContent(),true);
		}
		$result=array("code"=>$json['code'],"msg"=>$json['msg'],"price"=>$json['money']);
		return $result;			
    }    
    
    /**
     * 发起通知
	 * 提交参数:支付方式
     */
    function Submit_submit($type,$money)
    {
		
        $Arrs = array("act" =>'Instant_Notify',"pid" =>$this->Api_pid,"key" =>$this->Api_key,"type" =>$type,"money" =>$money);
		//设置请求内容
		$this->httpClient->setReqContent($this->Api_url.'api.php?'.http_build_query($Arrs));
		//后台调用
		if($this->httpClient->call()) {
			//设置结果参数
			$data = $this->httpClient->getResContent();
		}
		return $data;			
    }       
}
?>